<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *商品管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list0';
$manage_op=array('confirm','cancel','agree','disagree');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择商品！','error');
	}
}
$return=array();
$tabs=array(
	array('op'=>'edit','title'=>'添加商品','action'=>'goods.list'),
	
);
$return['status']=array('0'=>'下架','1'=>'上架','2'=>'售罄','3'=>'回收站');
//仓库中商品
if($_RQ['op']=='list0'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']='0';
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$tip='【温馨提示】：所属商户如果为“无”，表示商户已经不存在！排序，越大越靠前！<red>商品价格解释：如果门店设置了商品价格，将以门店价格为准！规格的库存，价格也是以门店的为准！</red>';
	$onepluginname=$this->model('goods')->is_onegoods($_SESSION['current_plugin'],$_RQ['pluginname']);
	if($onepluginname){//开启独立商品
			$params['onepluginname']=$onepluginname;
			$return['params']['onepluginname']=$onepluginname;
			$tip .='</br><red>【注意】：本场景已开启独立商品展示，只显示本场景下的商品！</red>';
	}else{
			$params['onepluginname']='';
			$tip .='</br><red>【注意】：本场景已开启独立商品展示，已剔除其他独立场景的商品！</red>';
	}
	$install = check_permission('jy_poster');
	if(!$install){
		$tip .='</br><red>【注意】：还未安装《活动海报》！商品详情不显示生成海报按钮！</red>';
	}
	$tip .='</br>【<red>一键更新商品权限</red>】：是指新版多选权限格式的更新（之前是单选）';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','paixu','title','image','pcate','ccate','price','status','createtime');
	$list=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>$tip,'edit'=>false,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'title','title'=>'商品名称','type'=>'string'),
			array('name'=>'image','title'=>'商品图片','type'=>'image'),
			array('name'=>'pcate','title'=>'一级分类','type'=>'string'),
			array('name'=>'ccate','title'=>'二级分类','type'=>'string'),
			array('name'=>'price','title'=>'价格','type'=>'string'),
			array('name'=>'pay','title'=>'库存','type'=>'string'),
			array('name'=>'coupon','title'=>'销量','type'=>'string'),
			//array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'coupon','title'=>'属性','type'=>'string'),
		),'action'=>array(
			array('type'=>'href','action'=>'goods.list','op'=>'edit','title'=>'编辑'),
		),'batch'=>array(
			array('type'=>'post','url'=>'jy_weishop/goods.list/setstatus1/','title'=>'一键上架'),
			array('type'=>'post','url'=>'jy_weishop/goods.list/setstatus2/','title'=>'一键售罄'),
			array('type'=>'post','url'=>'jy_weishop/goods.list/setstatus3/','title'=>'一键加入回收站'),
		)),
		'search_one'=>array('name'=>'title','title'=>'商品名称','add'=>false),

	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_update('jy_weishop_goods',array('status'=>3),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！您可以在回收站中还原该商品！');
}